<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">报名信息</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>报名信息</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：<select id="reg-search-key">
            <option value="">-请选择-</option>
            <option value="ksh">考生号</option>
            <option value="xm">姓名</option>
            <option value="kl">科类</option>
            <option value="zzmm">政治面貌</option>
        </select>
            <input id="reg-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="reg-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="reg-table" lay-filter="reg-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="reg-tab-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="export">
        <span class="layui-icon layui-icon-export" title="导出Word"></span>
    </a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="details">
        <span class="layui-icon layui-icon-about" title="详情"></span>
    </a>
</script>

<script type="text/html" id="reg-tab-toolbar">
    <a class="layui-btn layui-btn-primary layui-btn-md" lay-event="exportWord" title="批量导出Word">
        导出Word
    </a>
    <a class="layui-btn layui-btn-primary layui-btn-md" lay-event="exportExcel" title="批量导出Excel">
        导出Excel
    </a>
</script>

<script>
    layui.use(['form', 'table', 'util', 'config', 'admin', 'excel'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;
        let excel = layui.excel;

        // 渲染表格
        var renderTable = function () {
            table.render({
                elem: '#reg-table',
                // url: config.base_server + 'user_query.json',
                url: config.base_server + 'api-firebird/fireBird/getRegisterInfoList',
                method: 'GET',
                where: {
                    access_token: config.getToken().access_token,
                },
                title: '报名信息表',
                page: true,
                toolbar: '#reg-tab-toolbar',
                cols: [[
                    {type: 'checkbox'},
                    {type: 'numbers'},
                    {field: 'candiNum', title: '考生号'},
                    {field: 'candiName', title: '姓名'},
                    {field: 'birthday', title: '出生日期'},
                    {field: 'gender', title: '性别'},
                    {field: 'nation', title: '民族'},
                    {field: 'politicOutlook', title: '政治面貌'},
                    {field: 'graSchName', title: '毕业院校名'},
                    {field: 'regReside', title: '户口所在地'},
                    {field: 'exmPaperType', title: '应试卷种'},
                    {field: 'families', title: '科类'},
                    {align: 'center', toolbar: '#reg-tab-bar', title: '操作', width: 150}
                ]]
            });
        };
        renderTable();
        // 工具条点击事件
        table.on('tool(reg-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'details') { // 查看表字段
                showEditModel(data);
            } else if (layEvent === 'export') {
                layer.load();
                admin.req('api-firebird/fireBird/exportRegInfo', JSON.stringify(data), function (res) {
                    layer.closeAll('loading');
                    layer.alert(res.msg);
                }, 'POST');
            }
        });

        //显示表单弹窗
        var showEditModel = function (data) {
            admin.putTempData('t_reg_info', data);
            var title = data.candiNum + " - " + data.candiName + " - 报名信息";
            admin.popupCenter({
                title: title,
                path: 'pages/business/stu_details.html',
                area: ['800px', '740px'],
                offset: [0, 0]
            });
        };

        table.on('toolbar(reg-table)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            let layEvent = obj.event;
            let data = checkStatus.data;
            switch (layEvent) {
                case 'exportWord':
                    layer.load();
                    if (data.length <= 0) {
                        admin.req('api-firebird/fireBird/getRegisterInfoList', {}, function (res) {
                            data = res.data;
                        }, 'GET');
                    }
                    admin.req('api-firebird/fireBird/exportRegInfo', JSON.stringify(data), function (res) {
                        layer.closeAll('loading');
                        layer.alert(res.msg);
                    }, 'POST');
                    break;
                case 'exportExcel':
                    // let thead = ['考生号', '姓名', '出生日期', '性别', '证件类型', '证件号',
                    //     '学籍号', '考生类别', '外语语种', '外语口试', '外语听力', '民族',
                    //     '政治面貌', '毕业院校代码', '毕业院校名', '毕业类别', '考试类型',
                    //     '考生特征', '考生资格', '选考科目', '术科科目', '户籍类别', '户口所在地',
                    //     '残障类别', '录取通知邮寄地址', '收件人', '邮政编码', '联系手机', '联系电话',
                    //     '考生特长', '奖励和处分', '思想品德考核意见', '应试卷种', '科类'];
                    let thead = [{
                        candiNum: "考生号", candiName: "姓名", birthday: "出生日期", gender: "性别", docType: "证件类型",
                        docNum: "证件号", stuNum: "学籍号", stuType: "考生类别", foreignLan: "外语语种", oralExam: "外语口试",
                        listen: "外语听力", nation: "民族", politicOutlook: "政治面貌", graSchId: "毕业院校代码 ",
                        graSchName: "毕业院校名", graCate: "毕业类别", exmType: "考试类型", candiChara: "考生特征",
                        candiQua: "考生资格", selectSub: "选考科目", techSub: "术科科目", regResideCat: "户籍类别",
                        regReside: "户口所在地", disCate: "残障类别", admNoticeMailAddr: "录取通知邮寄地址", addressee: "收件人",
                        postalCode: "邮政编码", contactPhone: "联系手机", contactNum: "联系电话", special: "考生特长",
                        punishAndReward: "奖励和处分", moralEduEvalOpn: "思想品德考核意见", exmPaperType: "应试卷种", families: "科类"
                    }];
                    //如果未选中数据，则视为导出全部数据
                    if (data.length <= 0) {
                        admin.req('api-firebird/fireBird/getRegisterInfoList', {}, function (res) {
                            data = res.data;
                        }, 'GET');
                    }
                    let filterdata = [
                        "candiNum", "candiName", "birthday", "gender", "docType", "docNum", "stuNum",
                        "stuType", "foreignLan", "oralExam", "listen", "nation", "politicOutlook", "graSchId",
                        "graSchName", "graCate", "exmType", "candiChara", "candiQua", "selectSub", "techSub",
                        "regResideCat", "regReside", "disCate", "admNoticeMailAddr", "addressee", "postalCode",
                        "contactPhone", "contactNum", "special", "punishAndReward", "moralEduEvalOpn", "exmPaperType",
                        "families"];
                    data = excel.filterExportData(data, filterdata);
                    thead.push.apply(thead,data);
                    excel.exportExcel(thead,'报名信息表.xlsx','xlsx');
                    // table.exportFile(thead,data, 'xls');
                    break;
            }
        })
        $("#reg-btn-search").click(function () {
            let key = $("#reg-search-key").val();
            let value = $("#reg-search-value").val();
            if (key!='ksh')
                value = value + '%';
            table.reload('reg-table', {where: {searchKey: key,searchValue: value}})
        });
    });
</script>